package redis

import (
	"fmt"
	"github.com/go-redis/redis"
	"zc/rpc/appconfig"
	"zc/rpc/global"
)

func InitRedisApp() {
	var err error
	stu := appconfig.AppCon.RedisApp
	res := fmt.Sprintf("%s:%d", stu.Addr, stu.Pass)
	global.RedisClient = redis.NewClient(&redis.Options{
		Addr:     res,
		Password: "", // no password set
		DB:       0,  // use default DB
	})

	_, err = global.RedisClient.Ping().Result()
	fmt.Println(err)
	// Output: PONG <nil>
	if err != nil {
		fmt.Println("redis 连接失败", err)
		return
	}
	fmt.Println("redis 连接成功")
}
